package com.ruoyi.bizsys.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.bizsys.domain.AwardGroup;
import com.ruoyi.bizsys.service.IAwardGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 奖励分组Controller
 *
 * @author african-loan
 * @date 2022-06-22
 */
@RestController
@RequestMapping("/award/group")
public class AwardGroupController extends BaseController {
    @Autowired
    private IAwardGroupService awardGroupService;

    /**
     * 查询奖励分组列表
     */
    @PreAuthorize("@ss.hasPermi('bizsys:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(AwardGroup awardGroup) {
        startPage();
        List<AwardGroup> list = awardGroupService.selectAwardGroupList(awardGroup);
        return getDataTable(list);
    }

    /**
     * 导出奖励分组列表
     */
    @PreAuthorize("@ss.hasPermi('bizsys:group:export')")
    @Log(title = "奖励分组", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AwardGroup awardGroup) {
        List<AwardGroup> list = awardGroupService.selectAwardGroupList(awardGroup);
        ExcelUtil<AwardGroup> util = new ExcelUtil<AwardGroup>(AwardGroup.class);
        return util.exportExcel(list, "group");
    }

    /**
     * 获取奖励分组详细信息
     */
    @PreAuthorize("@ss.hasPermi('bizsys:group:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(awardGroupService.selectAwardGroupById(id));
    }

    /**
     * 新增奖励分组
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('bizsys:group:add')")
    @Log(title = "奖励分组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AwardGroup awardGroup) {
        return toAjax(awardGroupService.insertAwardGroup(awardGroup));
    }

    /**
     * 修改奖励分组
     */
    @PreAuthorize("@ss.hasPermi('bizsys:group:edit')")
    @Log(title = "奖励分组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AwardGroup awardGroup) {
        return toAjax(awardGroupService.updateAwardGroup(awardGroup));
    }

    /**
     * 删除奖励分组
     */
    @PreAuthorize("@ss.hasPermi('bizsys:group:remove')")
    @Log(title = "奖励分组", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(awardGroupService.deleteAwardGroupByIds(ids));
    }
}
